
<title>Item Control Page</title>
 

<?php 

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
   
require_once "../services/webservices.php";
require_once "index.php";
require_once('random_generator.php');  



if(isset($_POST['delete_category']))
{
    $isc_id = $_POST['isc_id'];
    $gw_id = $_POST['gw_id'];
    $itemspecialization = new itemspecialization();
    $itemspecialization->isc_id = $isc_id;
    $itemspecialization->gw_id = $gw_id;
    $itemspecialization->deleteitemspecializationdescriptorbyiscid();
    $itemspecialization->deleteitemspecializationbyiscid();
    // we have to delete the category and its desciptors
   
    //we have to delete all specific widget and specific widget pivot data for this general widget
    $swResponse = $itemspecialization->getspecificwidgetbygwid();
    $swXml = new SimpleXMLElement($swResponse);
    foreach($swXml->Item as $swItem)
    {
        $sw_id = $swItem->sw_id;
        $itemspecialization->sw_id = $sw_id;
        $itemspecialization->deletespecificwidgetpivotbyswid();
        $itemspecialization->deletespecificwidgetbyswid();
    }
    
   
    // we have to recreate the specific widget/pivot data
     $itemspecialization->createspecificitems();
    
}

if(isset($_POST['gw_id']) && isset($_POST['number_categories']) && isset($_POST['getdescriptors']) && isset($_POST['getitemoptions']))
{
   
   $gw_id = $_POST['gw_id']; 
    
  
    //need to get current categories for this specific widget. If one of the categories they are trying to add already exists, then dont add it.
    $itemspecializationObject = new itemspecialization();
    $itemspecializationObject->gw_id = $gw_id;
    $isobjectReturn = $itemspecializationObject->getitemspecializationbygwid();
    $isoXml = new SimpleXMLElement($isobjectReturn);
    $categoryArray = array();
    foreach($isoXml->Item as $isoItem)
    {
        $category = (string)$isoItem->category;
        $categoryArray[count($categoryArray) + 1] = $category;
    }
    
    
    
    $num_cat = $_POST['number_categories'];
    
   
    
    $tmp_num = 0;
    $addedNum = 0;
    //this is where we loop through the number of categories, thereby exposing their values for us
    while($tmp_num != $num_cat)
    {
       
        $tmp_num++;
        $cat_num = "category" . $tmp_num;
        $desc_num = "descriptors" . $tmp_num;
        
        $cat_value = $_POST[$cat_num];
      
        if(in_array($cat_value, $categoryArray))
        {
            echo '<br /><br /><br />';
            echo "<br /><b>Category '$cat_value' wasn't added because it already exists. </b><br /> ";
        }
        else
        {
            $num_descriptors_for_cat_string = $cat_num . "numberdescriptors";
            $num_descriptors_for_cat = $_POST[$num_descriptors_for_cat_string];
            
            $random = new RandomAlphaNumeric();
            $rand_string = $random->str_rand(20, 'alphanum'); 

            
            $getrequest = new itemspecialization();     
            $getrequest->gw_id = $gw_id;
            $getrequest->category = $cat_value;
            $getresponse = $getrequest->additemspecializationcategory();
            $xml = new SimpleXMLElement($getresponse);    
            $isc_id = $xml->item_id;  
            
?>  
            
<?php
            $tmp_option_num = 0;
          
            while($tmp_option_num != $num_descriptors_for_cat)
            {
               
                $tmp_option_num++;
                $category_descriptor_number = $cat_num . "descriptor" . $tmp_option_num;               
                $current_category_descriptor_value = $_POST[$category_descriptor_number];
                        
                    $getrequest = new itemspecialization();
                    $getrequest->isc_id = $isc_id;                  
                    $getrequest->descriptor = $current_category_descriptor_value;
                    $getresponse = $getrequest->additemspecializationdescriptor();                   
                    $xml = new SimpleXMLElement($getresponse);                   
                    $isd_id = $xml->item_id;
       
            }
            $addedNum++;
                
        }

         
    }
    if($addedNum > 0)
    {
        //check to see if this item has been specialized before. If so, then delete all old specific widget and specific widget pivot table data
        $getrequest = new itemspecialization(); 
        $getrequest->gw_id = $gw_id;
        $swResponse = $getrequest->getspecificwidgetbygwid();
        $swXml = new SimpleXMLElement($swResponse);
        $swCount = $swXml->Item_Count;
        if($swCount != 0)
        {
            foreach($swXml->Item as $swItem)
            {
                $current_sw_id = $swItem->sw_id;
                $getrequest->sw_id  = $current_sw_id;
                $getrequest->deletespecificwidgetpivotbyswid();
                $getrequest->deletespecificwidgetbyswid();
                
            }    
        }
        
         $getrequest = new itemspecialization();
         $getrequest->gw_id = $gw_id;
         $getrequest->createspecificitems();
        
    }
   
        
       
}  
    


    $result = 0;
    $error = "";
    if(isset($_POST['update_specialization']))
    {
       $numitems = $_POST['counted'];
     
       
       $temp_num = 0;
       
       $motherarray = array();
       $getarray = array();
       $getarray = $_POST;
       
      
       
       reset($getarray);    
     
       
       $price_array = array();
      
      $sw_id_array = $getarray['sw_id'];  
      $qty_array = $getarray['qty'];
      $weight_array = $getarray['weight'];
      $image_array = $getarray['image'];
      $price_array = $getarray['price'];
               
      $temp_num++; 
         
      $numberz = 0;
   
      $tempy = 0;
      $num = count($sw_id_array);
      while($numberz != $num)
      {   
           if(isset($_POST[$numberz]))
           {
               $temp_sw_id = $sw_id_array[$numberz];
               $temp_qty = $qty_array[$numberz]; 
               $temp_weight = $weight_array[$numberz]; 
               $temp_price = $price_array[$numberz]; 
               $temp_image = $image_array[$numberz]; 
               
             
              
                $getrequest = new itemspecialization();
                $getrequest->sw_id = $temp_sw_id;
                $getrequest->qty = $temp_qty;
                $getrequest->price = $temp_price;
                $getrequest->image = $temp_image;
                $getrequest->weight = $temp_weight;
                $getresponse = $getrequest->updatesw();
                $xml = new SimpleXMLElement($getresponse);
                $added = $xml->added;
                $added = (int)$added;
                $tempy++;
           }
            $numberz++;   
       
       }    
       print '<br /><br /><br /><br /><b>Items Updated: </b>' . $tempy;        
        
      }    
   
    if(isset($_POST['activate']))
    {                                                             
         
        $num_activated = $_POST['num_activated'];
        $num_temp_activated = 0;
        while($num_temp_activated != $num_activated)
        {
            if(isset($_POST[$num_temp_activated]))
            {
       
                $temp_sw_id = $_POST[$num_temp_activated];           
                $getrequest = new itemspecialization();
                $getrequest->sw_id = $temp_sw_id;
                $getresponse = $getrequest->activatespecificitem();
                $xml = new SimpleXMLElement($getresponse);
                $id_updated = $xml->sw_id;
            }
            $num_temp_activated++; 
        }
        
    }        
    if(isset($_POST['inactivate']))
    {     
       $num_items = $_POST['counted'];       
       $test_num = 0;
       while($test_num != $num_items)
       {
           if(isset($_POST[$test_num]))
           {
             $current_sw_id = $_POST[$test_num];          
             $getrequest = new itemspecialization();
             $getrequest->sw_id = $current_sw_id;
             $getresponse = $getrequest->deactivatespecificitem();
           }
            
            $test_num++;   
       }
       
    }
    
    if (isset($_POST['update']))
    { 
        
        if($_POST['specialized'] == "false")
        {
           
            ///Create the object and send the values to it.
            $updateRequest = new item();
            $updateRequest->gw_id = $_POST['gw_id'];
            $updateRequest->price = $_POST['price'];
            $updateRequest->item_name = $_POST['gw_name'];
            $updateRequest->weight = $_POST['weight'];
            $updateRequest->category_id = $_POST['category_id'];
            $updateRequest->general_description = $_POST['general_description'];
            $updateRequest->description = $_POST['description'];
            $updateRequest->imageurl = $_POST['image']; 
            $updateRequest->packing = $_POST['packing'];
            $updateRequest->in_stock = $_POST['in_stock'];
            
            $updateResponse = $updateRequest->updateitem();   
        }
        else
        {
            
            ///Create the object and send the values to it.
            $updateRequest = new item();
            $updateRequest->gw_id = $_POST['gw_id'];
      
            $updateRequest->gw_name = $_POST['gw_name'];      
            $updateRequest->category_id = $_POST['category_id'];
            $updateRequest->general_description = $_POST['general_description'];
            $updateRequest->description = $_POST['description'];
            $updateRequest->image = $_POST['image']; 
            $updateRequest->packing = $_POST['packing'];
               
            $updateResponse = $updateRequest->updatespecializedgeneralitem();          
        }
        $xml = new SimpleXMLElement($updateResponse);
        $updated = $xml->updated;
        $gw_id = $xml->gw_id;
           
        if ($updated)
        {
            echo '<br /><br /><br /><br /><b>Update Complete</b>';
        }
        else
        {
            echo "Error: " . $updateResponse->reason;
        }
    } 
    
    if(isset($_POST['Edit_Button']) || isset($_GET['Edit_Button']))
    {  
      
        if (isset($_POST['gw_id']) || isset($_GET['gw_id']))
        {      
            if(isset($_POST['gw_id']))
            {
                $gw_id = $_POST['gw_id'];
            }
            else
            {
                $gw_id = $_GET['gw_id'];   
            }
            
            $getrequest1 = new itemspecialization();
            $getrequest1->gw_id  = $gw_id;
            $getrequest1 = $getrequest1->getitemspecializationcategorybygwid();
            $xml1 = new SimpleXMLElement($getrequest1);
            $num = 0;
            foreach($xml1->Item as $eachitem1)
            {
                
                $num++;
            }
            if($num !=0)
            {
                $specialized = "true";   
            }
            else
            {
                $specialized = "false";
            }
            
            $getRequest = new item();
            $getRequest->gw_id = $gw_id;
            $getResponse = $getRequest->getitembyid();
            $xml = new SimpleXMLElement($getResponse);
            $Item_Count = $xml->Item_Count;
            if($Item_Count > 0)
            {
                foreach ($xml->Item as $eachItem)         
                {
                    $Item_Count = $eachItem->Item_Count;
                    $gw_id = $eachItem->gw_id;
                    $gw_name = $eachItem->gw_name;            
                    $category_id = $eachItem->category_id;
                    $category = $eachItem->category;
                    $general_description = $eachItem->general_description;
                    $description = $eachItem->description;
                    $desc_length = strlen($description);
                    $description = (string)$description;
                    $description = (string)$description;   
                    $image = $eachItem->image; 
                    $price = $eachItem->price; 
                    $in_stock = $eachItem->in_stock;  
                    $length = $eachItem->length;
                    $packing = $eachItem->packing;
                    $weight = $eachItem->weight; 
                    
                    
                }   
                $result = 1;
            }
            else
            {
                $result = 0;
                $error = "Error: A non-existent item was specified.";
                }
        }
        else
        {
            $result = 0;
            $error = "Error: No gw_id was specified.";
            }
    }
    if($result == 1)
    {
           
?>
    <br />   
    <br />
    
     <div class="center1">
     <div class="center2">
     <div class="smallcore">
     <div class= "center1">
     <div class="center2">
     <b>General Item Information</b>
     </div>
     </div>
     <br /><br />   
    
    <form action="updateitem.php" method="post" name="updateitem">    
        <input name="gw_id" id="gw_id" type="hidden" value="<?php echo $gw_id;?>" />
        <strong>Item ID:   </strong><?php echo $gw_id;?>
        <br />
        <strong>Item Name:</strong><br />
        <input name="gw_name" id="gw_name" type="text" value="<?php echo $gw_name;?>" />
        <br />
        <strong>Category:</strong><br />
        <select name="category_id">
        <option value="<?php echo $category_id?>"><?php echo $category?></option>
            <?php
            //this gathers all the categories in the database and displays them as options for the selectbox
            $getRequest = new itemcategory();
            $getResponse = $getRequest->getallitemcategories();

            //Loop through returned XML and display all items        
            $xml = new SimpleXMLElement($getResponse);

            $Item_Count = $xml->Item_Count;

            if($Item_Count > 0)
            {
       
            foreach ($xml->Item as $eachitem)         
            {
                $category_id = $eachitem->category_id;
                $category = $eachitem->category;            
                ?>
                <option value="<?php echo $category_id;?>" onclick="document.updatecategoryform.submit();"><?php echo $category;?></option>
                <?php
            }
       }
            else
            {
            ?>
            <option value="0">No Categories Found.</option>
            <?php
       }        
            ?>
            </select> 
            <br />
   
    
   
        <strong>General Description:</strong></td><br />
        <input name="general_description" id="general_description" type="text" value="<?php print $general_description;?>" />
        <br />
    
 
        <strong>Description:</strong></td><br />
        <textarea name="description" cols="60" rows="10"><?php print urldecode($description);?></textarea>
        
        <br />
    

        <strong>Image URL:</strong><br />
        <input name="image" id="image" type="text" size="83" value="<?php echo urldecode($image);?>" />
        <br /> 
    <?php
    if($specialized == "false")
    {
            ?>
            
        
        <input type="hidden" id="specialized" name="specialized" value="false">
        <strong>Price:</strong><br />
        <input name="price" id="price" type="text" size="20" value="<?php echo $price;?>" />
        <br /> 
                                       
        <strong>Number In Stock:</strong><br />
        <input name="in_stock" id="in_stock" type="text" size="20" value="<?php echo $in_stock;?>" />
        <br />
    
        <strong>Weight:</strong><br />
        <input name="weight" id="weight" type="text" size="20" value="<?php echo $weight;?>" />
        <br /> 
        <?php
    }
    else
    {

        echo '<input type="hidden" id="specialized" name="specialized" value="true">';         

        
           
        
    }
    ?>

        <strong>Packing:</strong><br />

            <select name="packing">
                <option value="<?php echo $packing; ?>"><?php echo $packing; ?></option>
                <option value="alone">alone</option>
                <option value="grouped">grouped</option>
            </select>

    
 
    
    
    
    


          <input type="hidden" name="Edit_Button" id="Edit_Button" value="Edit_Button"><br />
          <input name="update" value="Update Item Information" type="submit" class="button" />                      
    </form>
    <form action="item_options.php" method="GET" id="item_specialization">
          <input type="hidden" name="gw_id" id="gw_id" value="<?php echo $gw_id?>"> 
          <input type="submit" name="submit" value="Add Specialization Category">
    </form><br />
    
    </div>
    </div>
    </div> 
    <br />
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br /><br /><br /><br /> 
    <br /><br /><br /><br /><br /><br />
    <br /><br /><br /> 
    <?php
    
    if($specialized == "false")
    {
       echo "<br /><br /><br /><br /><br /><br /> 
       <br /><br /><br /><br /><br /><br />    
       <br /><br /><br /><br /><br /><br />";
    }    
    

    $getrequest = new itemspecialization();
    $getrequest->gw_id = $gw_id;
    $getresponse = $getrequest->getitemspecializationcategorybygwid();
    $xml = new SimpleXMLElement($getresponse);
    $isCount = $xml->Item_Count;
    //this gets all item specialization for this gw_id
    if($isCount != 0)
    {   
        echo '<div class="smallcore">';
        echo '<h3><b>Current Item Specialization Categories</b></h3>';
     
        
        foreach($xml->Item as $eachitem)
        {   
            $isc_id = $eachitem->isc_id; 
            $gw_id = $eachitem->gw_id;
            $category = $eachitem->category;
            
          
            echo '<form action="update_delete_item_specialization.php" method="GET">';
            echo '<input type="hidden" name="category" id="category" value="' . $category . '">';

            echo '<b>' . $category . '</b>';
            echo '<select name="isn">';
            
            $getrequest = new itemspecialization();
            $getrequest->isc_id = $isc_id;
          
            $getresponse = $getrequest->getitemspecializationdescriptorbyiscid();
                                       
            $xml = new SimpleXMLElement($getresponse);

               
                foreach($xml->Item as $eachitem)
                {
                    $id = $eachitem->id;
                    $isc_id = $eachitem->isc_id;
                    $descriptor = $eachitem->descriptor;
                   
                    echo '<option value="' . $tmp_num . '">' . $descriptor . '</option>';

                }           
               echo '</select></form>';
              

                   echo '<form action="update_delete_item_specialization.php" method="GET">';
                   echo '<input type="hidden" name="category" id="category" value="' . $category . '">';
                  
                   echo '<input type="hidden" id="isc_id" name="isc_id" value="' . $isc_id . '">'; 
                   echo '<input type="hidden" id="isd_id" name="isd_id" value="' . $id . '">';
                   echo '<input type="hidden" id="gw_id" name="gw_id" value="' . $gw_id . '">'; 

                   echo '<input type="submit" id="update" name ="update_is" value="Update ' . $category . '">'; 
                   echo '</form>';
                   echo '<form action="updateitem.php" method="POST">';
                   echo '<input type="hidden" name="category" id="category" value="' . $category . '">';
                    echo '<input type="hidden" id="isc_id" name="isc_id" value="' . $isc_id . '">'; 
                   echo '<input type="hidden" id="isd_id" name="isd_id" value="' . $id . '">';
                   echo '<input type="hidden" id="gw_id" name="gw_id" value="' . $gw_id . '">'; 
                   echo '<input type="hidden" id="Edit_Button" name="Edit_Button" value="Edit_Button"/>';
                   echo '<input type="submit" id="delete_category" name = "delete_category" value="Delete ' . $category . '">';   
                   
                   echo '</form>'; 
                  
                
      }
       echo '</div>'; 
       
    } 
     
     
?>
     
   
                          

   
                              
                                
                    
<?php 

            $getrequest2 = new itemspecialization();
            $getrequest2->gw_id = $gw_id;
            $getresponse2 = $getrequest2->getactivespecificwidgetbygwid();
            $xml2 = new SimpleXMLElement($getresponse2);
            $sw_Count = $xml2->Item_Count;
            if($sw_Count != 0)
            {
                
?>
    
    
       
        
   <br /><br />
   <div class="smallcore">
   <b><big>Active Specialized Items</big></b>
      
       <br /><br /><br />
        <form action="updateitem.php" method="POST" id="updateitem">
       

<?php
                
                $sw_id_count = 0;
                foreach($xml2->Item as $eachitem2)
                {
                   
                    $sw_id_is = $eachitem2->sw_id;
                   
                    $qty = $eachitem2->qty;
                    $price = $eachitem2->price;
                    $weight = $eachitem2->weight;
                    $image = $eachitem2->image;
                    $active = $eachitem2->active;
                    $active = (string)$active;
                    if($active == "active")
                    {
                        
                        $getrequest3 = new itemspecialization();
                        $getrequest3->sw_id = $sw_id_is;
                        $getresponse3 = $getrequest3->getisdidbyspecificwidgetid();
                        $xml3 = new SimpleXMLElement($getresponse3);
                        $i_c = $xml3->Item_Count;
                        $descriptor_array = array();
                        foreach($xml3->Item as $eachitem3)
                        {
                          
                            $isd_id_is = $eachitem3->isd_id;
                            $isd_id_is = (string)$isd_id_is;
                            
                            $getrequest4 = new itemspecialization();
                            $getrequest4->isd_id = $isd_id_is;

                            $getresponse4 = $getrequest4->getitemspecializationdescriptorbyisdid();
                            $xml4 = new SimpleXMLElement($getresponse4); 
                          
                            foreach($xml4->Item as $eachitem4)
                            {
                               
                                $isdid_isc_id = $eachitem4->isc_id;
                                
                                $getrequest6 = new itemspecialization();
                                $getrequest6->isc_id = $isdid_isc_id;
                                $getresponse6 = $getrequest6->getitemspecializationcategorybyiscid();
                                $xml6 = new SimpleXMLElement($getresponse6);
                             
                                foreach($xml6->Item as $eachitem6)
                                {
                                    $category = $eachitem6->category; 
                                    $category = (string)$category; 
                                   
                                   
                                }
                                
                                $descriptor = $eachitem4->descriptor;
                                $descriptor = (string)$descriptor; 
                                
                            }
                            $descriptor_array[$category] = $descriptor;      
                           
                            ksort($descriptor_array);
                        
                           
                            
                        }
                                        
                            $des_string = ""; 
                          
                            foreach($descriptor_array as $key => $value)
                            {
                                $category1 = $key;
                                $descriptor1 = $value;
                                $des_string .= $category1 . "=" . $descriptor1 . ", ";
                                   
                            }
                            $des_string = rtrim($des_string, ", ");
                        echo '<div class="smallcore">';
                        echo '<input type="checkbox" id="' . $sw_id_count . '" name="' . $sw_id_count . '" value="' . $sw_id_is . '">';
                        echo '<br />';
                        echo '<b>Specific Item:</b>' . $des_string;
                        echo '<br />'; 
                        echo '<b>Item ID:</b>' . $sw_id_is;                                               
                        echo '<input type="hidden" id="sw_id[' . $sw_id_count . ']" name="sw_id[' . $sw_id_count . ']" value="' . $sw_id_is . '">'; 
                        echo '<input type="hidden" id="Edit_Button" name="Edit_Button" value="Edit_Button">';
                        echo '<br />'; 
                        echo '<b>Qty:</b><input type="text" name="qty[' . $sw_id_count . ']" id="qty[' . $sw_id_count . ']" value="' . $qty . '">';
                        echo '<br />'; 
                        echo '<b>Weight:</b><input type="text" name="weight[' . $sw_id_count . ']" id="weight[' . $sw_id_count . ']" value="' . $weight . '">';
                        echo '<br />'; 
                        echo '<b>Image Url:</b><input type="text" size="83" name="image[' . $sw_id_count . ']" id="image[' . $sw_id_count . ']" value="' . $image . '">';
                        echo '<br />'; 
                        echo '<b>Price:</b><input type="text" name="price[' . $sw_id_count . ']" id="price[' . $sw_id_count . ']" value="' . $price . '">';
                        echo '<br />';
                        echo '<br />'; 
                        
                        $sw_id_count++;   
                        echo '</div>';
                    }
                    
                   
                        
                }
               
                echo '<input type="hidden" id="gw_id" name="gw_id" value="' . $gw_id . '">';             
                $counted = $sw_id_count;
              
            
           
                  
                  echo '<input type="hidden" id="counted" name="counted" value="' . $counted . '">';
                  echo '<input type="submit" id="update_specialization" name="update_specialization" value="update">';
                  echo '<input type="submit" id="inactivate" name="inactivate" value="inactivate">';        
                  
                  
                  echo '</form>';
                 
                  echo '<br />';
                  echo '</div>';
           }
     ?>
     
    
 
 
    <?php
        $getrequest = new itemspecialization();
        $getrequest->gw_id = $gw_id;
        $getresponse = $getrequest->getinactivespecificwidgetbygwid();
        $xml = new SimpleXMLElement($getresponse);
       
        $Item_Count = $xml->Item_Count;
        $Item_Count = (int)$Item_Count;
        
        if ($Item_Count != 0)
        {
            
            $inactive = "true"; 
           
            if(!isset($_POST['show']))
            { 
                if(isset($_POST['gw_id']))
                {
                    $gw_id = $_POST['gw_id'];       
                } 
                if(isset($_GET['gw_id']))
                {
                    $gw_id = $_GET['gw_id'];
                } 
                
                
                
                echo '<div class="smallcore">';
                echo '<b><big>Show Available Inactive Items</big></b><br /><br />';      
                echo '<form action="updateitem.php" method="POST">';
                echo '<input type="hidden" id="Edit_Button" name="Edit_Button" value="Edit_Button">';
                echo '<input type="hidden" id="gw_id" name="gw_id" value="' . $gw_id . '">';
                echo '<input type="submit" id="show" name="show" value="show">';
                echo '</form>'; 
                echo '</div>';
                
            }
            else
            {
                
                echo '<div class="smallcore">';
                echo '<b><big>Available Inactive Items</big></b><br /><br />';   
             
               
                $sw_id_count = 1; 
                ?>
               
                        
                        <form action="updateitem.php" method="POST" id="upd_itm">
                            
                 <?php 
                  $build_num = 0;   

                                                                                                        
                    $getrequest2 = new itemspecialization();
                    $getrequest2->gw_id = $gw_id;
                    $getresponse2 = $getrequest2->getspecificwidgetbygwid();
                    $xml2 = new SimpleXMLElement($getresponse2);
                   
                   
                    foreach($xml2->Item as $eachitem2)
                    {
                        $sw_id_inactive = $eachitem2->sw_id;
                        $sw_id_inactive = (string)$sw_id_inactive;
                        $qty = $eachitem2->qty;
                        $price = $eachitem2->price;
                        $weight = $eachitem2->weight;
                        $image = $eachitem2->image;
                        $active = $eachitem2->active;
                        $active = (string)$active;
                        if($active == "inactive")
                        {   
                           
                            if($inactive == "true")
                            {
                                $sw_id_inactive = (string)$sw_id_inactive;   
                                $getrequest3 = new itemspecialization();
                                $getrequest3->sw_id = $sw_id_inactive;
                                $getresponse3 = $getrequest3->getisdidbyspecificwidgetid();
                                $xml3 = new SimpleXMLElement($getresponse3);
                                $i_c = $xml3->Item_Count;
                                $descriptor_concat = "";
                                $descriptor_array = array();
                                foreach($xml3->Item as $eachitem3)
                                {
                                    $isd_id_is = $eachitem3->isd_id;
                                    $isd_id_is = (string)$isd_id_is;
                                    
                                    $getrequest4 = new itemspecialization();
                                    $getrequest4->isd_id = $isd_id_is;
                                    $getresponse4 = $getrequest4->getitemspecializationdescriptorbyisdid();
                                    $xml4 = new SimpleXMLElement($getresponse4); 
                                    foreach($xml4->Item as $eachitem4)
                                    {
                                        $isdid_isc_id = $eachitem4->isc_id;
                                        
                                        $getrequest6 = new itemspecialization();
                                        $getrequest6->isc_id = $isdid_isc_id;
                                        $getresponse6 = $getrequest6->getitemspecializationcategorybyiscid();
                                        $xml6 = new SimpleXMLElement($getresponse6);
                                        foreach($xml6->Item as $eachitem6)
                                        {
                                            $category = $eachitem6->category; 
                                            $category = (string)$category;  
                                        }
                                        
                                        $descriptor = $eachitem4->descriptor;
                                        $descriptor = (string)$descriptor;   
                                    }
                                    $descriptor_array[$category] = $descriptor;
                                    ksort($descriptor_array);
                                }
                                
                                $des_string = "";  
                                foreach($descriptor_array as $key => $value)
                                {
                                    $category1 = $key;
                                    $descriptor1 = $value;
                                    echo  "<b>" . $category1 . ":</b>" . $descriptor1 . "<br />";
                                       
                                }
                                 
                                print $des_string;
                                
                                ?>
                                        
                                        <input type="checkbox" id="<?php echo $build_num;?>" name="<?php echo $build_num;?>" value="<?php echo $sw_id_inactive?>"><br />
                                       
                                
                            <?php  
                            $build_num++;   
                            }
                        }
                        
                    }
                    
                    
                    ?>
                        <input type="hidden" id="nun_activated" name="num_activated" value="<?php echo $build_num;?>">
                     <input type="hidden" id="Edit_Button" name="Edit_Button" value="Edit_Button">    
                     <input type="hidden" id="gw_id" name="gw_id" value="<?php echo $gw_id?>">
                         <br />
                        <?php echo $descriptor_concat;?><input type="submit" id="activate" name="activate" value="activate">
                     
                     </form>
                   </div> 
                
                <br /><br />  
                 <?php   
                 
                            
             
                echo '</div>';
                echo '</div>';
                
           }
       
       }
       else if($specialized == "true")
       {
           echo '<b><h3>No Inactive Items</h3><b><br /><br /><br /><br />';
       } 
      

    }
    


?>
 


